package org.galaxyworld.flycode.config;

import com.google.common.base.Splitter;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

import java.util.List;

public class ConfigFile {

    private PropertiesConfiguration config;

    public ConfigFile(PropertiesConfiguration config) {
        this.config = config;
    }

    public void setValue(String key, String value) {
        config.setProperty(key, value);
    }

    public void save() {
        try {
            config.save();
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
    }

    public String getString(String key) {
        return config.getString(key);
    }

    public boolean getBoolean(String key) {
        return config.getBoolean(key);
    }

    public List<String> getStringList(String key) {
        return getStringList(key, ",");
    }

    public List<String> getStringList(String key, String separator) {
        return Splitter
                .on(separator)
                .trimResults()
                .omitEmptyStrings()
                .splitToList(getString(key));
    }

    public static String keywordPostfix() {
        return "Data";
    }

}
